package br.com.douglasramiro.controlefinanceiro.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.xseam.validation.Email;
import org.xseam.validation.Pattern;
import org.xseam.validation.Range;

@Entity
@Table(name="TS_USUARIO")
@Name("usuario")
@AutoCreate
@NamedQueries({
	@NamedQuery(name="usuario.ativarConta",query="Select u from Usuario u where u.usuario = :user and u.senha = :senha"),
	@NamedQuery(name="usuario.logar",query="Select u from Usuario u where u.usuario = :user")
})
public class Usuario implements Serializable{
	private static final long serialVersionUID = 1132894722619561906L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="ID_USUARIO")
	private Long id;
	
	@Column(name="NOME",length=80,nullable=false)
//	@Range(min=5,max=80,message="O nome deve ter entre 5 e 80 caracteres.")
	private String nome;
	
	@Column(name="USUARIO",length=20,nullable=false,unique=true)
//	@Range(min=5,max=20,message="Informe um nome de usuário entre 5 e 20 caracteres.")
	@Pattern(regexPattern="[a-zA-Z_\\.0-9]+", message="Caracteres válidos: a-z A-Z _ . 0-9")
	private String usuario;
	
	@Column(name="EMAIL",length=100,nullable=false,unique=true)
	@Email
	private String email;
	
	@Column(name="SENHA",length=100,nullable=false)
//	@Range(min=5,max=20,message="Informe uma senha entre 5 e 20 caracteres.")
	private String senha;
	
	@Column(name="TELEFONE", length=14)
	private String telefone;
	
	@Column(name="STATUS")
	private Integer status;
	
	@Transient
//	@Range(min=5,max=20,message="Informe uma senha entre 5 e 20 caracteres.")
	private String confSenha;

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}
	

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public String getConfSenha() {
		return confSenha;
	}

	public void setConfSenha(String confSenha) {
		this.confSenha = confSenha;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getUsuario() {
		return usuario;
	}

	public void setUsuario(String usuario) {
		this.usuario = usuario;
	}

	public String getSenha() {
		return senha;
	}

	public void setSenha(String senha) {
		this.senha = senha;
	}

	public String getTelefone() {
		return telefone;
	}

	public void setTelefone(String telefone) {
		this.telefone = telefone;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		return obj instanceof Usuario && (((Usuario)obj).getId().equals(this.id));
	}
}